﻿using Kele.Core.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace Kele.Activity.Web.Controllers
{
    [ApiVersion("1.0")]
    [Route("api/v{version:apiVersion}/{controller}")]
    [Authorize]
    public abstract class SiteApiController : ApiController
    {
        protected int MerchantId
        {
            get
            {
                var sid = User.Claims.First(claim => claim.Type == "merchant_id").Value;
                int.TryParse(sid, out var id);
                return id;
            }
        }

        protected string OpenId => User.Claims.First(claim => claim.Type == "openid").Value;
        protected string UserId => User.Claims.First(claim => claim.Type == "openid").Value;
    }
}